var express = require('express');
var router = express.Router();

// -- ----------- 严晴---------- --

var { customersService,
    getSalesToCustomersService,
    delSalesToCustomersService,
    getModifyCustomersService,
    modifyCustomersService,
    getCustomersService,getCustomersAllId
} = require('../service/customersService');

//  新增客户
router.post('/addCustomers', async function (req, res, next) {
    var customers = req.body;
    // console.log('111', customers);
    res.send(await customersService(customers))
});

//  获取销售员的客户
router.post('/getSalesToCustomers', async function (req, res, next) {
    var data = req.body;
    // console.log('111', data.belongToSales);
    res.send(await getSalesToCustomersService(data))
});

//  删除销售员的客户
router.post('/deleteCustomers', async function (req, res, next) {
    var { _id } = req.body;
    // console.log('111', _id);
    res.send(await delSalesToCustomersService(_id))
});

//  获取修改销售员的客户
router.post('/getModifyCustomers', async function (req, res, next) {
    var { _id } = req.body;
    // console.log('111', _id);
    res.send(await getModifyCustomersService(_id))
});

//  确认修改客户的数据
router.post('/modifyCustomers', async function (req, res, next) {
    var { _id, name, age, gender, phone } = req.body;
    // console.log('111', customersData);
    res.send(await modifyCustomersService({ _id, name, age, gender, phone }))
});


//  获取管理员页面的客户信息
router.get('/getCustomers', async function (req, res, next) {
    var data = req.query;
    res.send(await getCustomersService(data))
});

// 获取所有客户
router.get('/getCustomersAllId', async function (req, res, next) {
    res.send(await getCustomersAllId( req.query))
});

module.exports = router;